#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<string> s;
int n, m;
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

bool Check(int x, int y) {
  return x > 0 && x <= n && y > 0 && y <= m && s[x - 1][y - 1] != 'x';
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    int k;
    int x, y, d;

    cin >> n >> m >> k;
    cin >> x >> y >> d;
    s.clear();
    s.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    s[x - 1][y - 1] = '*';
    for (int i = 0; i < k; i++) {
      int next_x = x + dir[d][0], next_y = y + dir[d][1];

      if (Check(next_x, next_y)) {
        x = next_x;
        y = next_y;
        s[x - 1][y - 1] = '*';
      } else {
        (d += 1) %= 4;
      }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (s[i][j] == '*') {
          ans++;
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}